package com.zhangwei.yueshijia.base;

import android.app.Application;

import com.umeng.analytics.MobclickAgent;
import com.zhangwei.yueshijia.net.DefaultNetChangeObserver;
import com.zhangwei.yueshijia.net.NetworkStateReceiver;

/**
 * 第三方的sdk
 * 网络监听
 * 数据库的升级操作
 * 第三方框架全局配置
 * app应用配置
 * 
 */
public class BaseApp extends Application {
    public static BaseApp app;
    public DefaultNetChangeObserver defaultNetChangeObserver;

    @Override
    public void onCreate() {
        super.onCreate();
        app = this;
        registerNetworkStateReceiver();
        //初始化友盟统计分析
        MobclickAgent.setScenarioType(this, MobclickAgent.EScenarioType.E_UM_NORMAL);
//        CrashHandler.getInstance().init(this);
//        CrashHandler.getInstance().collectDeviceInfo(this);
    }

    public void registerNetworkStateReceiver() {
        NetworkStateReceiver.registerNetworkStateReceiver(this);
        defaultNetChangeObserver = new DefaultNetChangeObserver(this);
        NetworkStateReceiver.registerObserver(defaultNetChangeObserver);
    }

    public void unRegisterNetworkStateReceiver() {
        NetworkStateReceiver.unRegisterNetworkStateReceiver(this);
        NetworkStateReceiver.removeRegisterObserver(defaultNetChangeObserver);

    }


    public static BaseApp getInstance() {
        return app;
    }
}
